#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Date  :     2022/1/19 14:31
    Desc  :
--------------------------------------
"""
from django_http_log.serializers import DynamicFieldsModelSerializer
from rest_framework import serializers

from person.models import *


class CaseBaseSerializer(DynamicFieldsModelSerializer):
    caseModuleName = serializers.SerializerMethodField()

    class Meta:
        model = CaseBase

        fields = '__all__'

    def get_caseModuleName(self, obj):
        if obj.caseModuleId:
            queryset = CaseModule.objects.filter(id = obj.caseModuleId, deleted = False)
            if queryset.count() != 0:
                return queryset.first().name
        return None
